package com.itjiange;

/**
 * 售卖口香糖的状态
 *
 * @author ItJianGe
 * @data 2024/8/20 17:18
 */
public class SoleChewStatus implements Status {

    private GumballMachine gumballMachine;

    public SoleChewStatus(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertCoin() {
        System.out.println("口香糖正在出货，无需投币");
    }

    @Override
    public void undoCoin() {
        System.out.println("口香糖正在出货，无法退款");
    }

    @Override
    public void turnCrank() {
        System.out.println("口香糖正在出货，无需重复转动曲柄");
    }

    @Override
    public void dispense() {
        if (gumballMachine.getChewCount() > 0) {
            System.out.println("口香糖正在出货中，请稍等");
            gumballMachine.releaseChew();
            gumballMachine.setStatus(gumballMachine.getNoCoinStatus());
        } else {
            System.out.println("口香糖已售罄，无法出货");
            gumballMachine.setStatus(gumballMachine.getSoleChewEmptyStatus());
        }
    }
}
